package com.ruoyi.common.utils;

import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.Properties;


public class PropertiesUtils {
    public static final String PROPERTIES_NAME = "config.properties";

    private static Properties props = new Properties();
    private static PropertiesUtils instance = new PropertiesUtils();

    public static PropertiesUtils getInstance(){
        return instance;
    }

    private PropertiesUtils(){
        props = new Properties();
        try{
            ClassPathResource resource = new ClassPathResource(PROPERTIES_NAME);
            if (!resource.exists()) {
                throw new IllegalArgumentException("file:" + resource.getFile().getAbsolutePath() + " not exist");
            }
            props.load(resource.getInputStream());
        }catch(IOException ioe){
            ioe.printStackTrace();
            return;
        }
    }


    public static String get(String key)  {

        return props.getProperty(key);
    }

}
